package com.map6;

import com.baidu.mapapi.GeoPoint;
import osb.map.net.BusSocket;
import osb.map.net.DataGPS;
import osb.map.net.DataPackage;
import osb.map.net.msgType;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class TestActivity extends Activity {
	Button button1;
	public static TestActivity staticLocationChangeTestActivity;
	private Thread thread;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test);
        staticLocationChangeTestActivity = this;
        findView();
        setClick();
    }

	private void findView() {
		button1 = (Button)findViewById(R.id.btn_open);
	}

	private void setClick() {
		button1.setOnClickListener(new OnClickListener() {
			

			@Override
			public void onClick(View v) {
				thread = new Thread(new BusSocket()); 
				thread.start();
				
				
//			    GeoPoint p1 = new GeoPoint( (int) (26.033754 * 1E6), (int) (119.215354 * 1E6));
//				GeoPoint p2 = new GeoPoint( (int) (26.029014 * 1E6), (int) (119.220421 * 1E6));
//				GeoPoint p3 = new GeoPoint( (int) (26.027163 * 1E6), (int) (119.217905 * 1E6));
//				
////				GeoPoint pt = new GeoPoint((int)(location.getLatitude()*1e6),(int)(location.getLongitude()*1e6));

				
				new Thread(new SendThread()).start();
				
//				float localX=(int) (26.033754 * 1E6);
//				float localY=(int) (119.215354 * 1E6);

//				if(thread!=null)
//				{
//					DataPackage data=new DataPackage(msgType.DataGPS);
//					data.dataGPS=new DataGPS(1, 1.9, 1.9);
//					BusSocket.Public_Static_BusSocket.sendMsg(data);
//				}
			}
		});
	}
	public class SendThread extends Thread
    {
		int count = 0;
		
		public SendThread()
		{
			
		}
		
		@Override
		public void run() {
			while(true)
            {
				if(count < 3)
				{
					count ++;
					 try
		                {
		                    Thread.sleep(3000);
		                }
		                catch (InterruptedException e)
		                {
		                    e.printStackTrace();
		                }
		                switch (count) {
						case 1:
							float localX1=(float) (26.012754 );
							float localY1=(float) (119.216354 );

							if(thread!=null)
							{
								DataPackage data1=new DataPackage(msgType.DataGPS);
								data1.dataGPS=new DataGPS(2, localX1, localY1);
								BusSocket.Public_Static_BusSocket.sendMsg(data1);
							}
							break;
						case 2:
//							float localX2=(float) (26.033754  );
//							float localY2=(float) (119.215354 );

							float localX2=(float) (26.012254  );
							float localY2=(float) (119.211054 );
							if(thread!=null)
							{
								DataPackage data2=new DataPackage(msgType.DataGPS);
								data2.dataGPS=new DataGPS(2, localX2, localY2);
								BusSocket.Public_Static_BusSocket.sendMsg(data2);
							}
							break;
						case 3:
							float localX3=(float) (26.012754  );
							float localY3=(float) (119.214354  );

							if(thread!=null)
							{
								DataPackage data3=new DataPackage(msgType.DataGPS);
								data3.dataGPS=new DataGPS(2, localX3, localY3);
								BusSocket.Public_Static_BusSocket.sendMsg(data3);
							}
							break;

						default:
							break;
						}
		                if(count == 3)
		                {
		                	count = 0;
		                }
				}
               
            }
		}
    }
}